package com.tfswx.jcyw.dmzc.component;

import cn.hutool.core.bean.BeanUtil;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;

/**
 * @author 张述江
 * @date 2023/5/31
 */
public class MyComboBox extends JComboBox<String> {

    public MyComboBox(Object obj, String zdmc, List<String> dataList) {
        for (String s : dataList) {
            addItem(s);
        }

        setSelectedItem(BeanUtil.getProperty(obj, zdmc));

        addItemListener(e -> BeanUtil.setProperty(obj, zdmc, getSelectedItem()));
    }
}
